package com.wh1200.mybatis.xmlless.config

import com.wh1200.mybatis.xmlless.enums.XmllessDbType
import com.baomidou.mybatisplus.core.MybatisConfiguration
import com.wh1200.mybatis.xmlless.handler.JsonTypeHandler
import org.apache.ibatis.binding.MapperRegistry
import org.apache.ibatis.mapping.ResultMap
import org.apache.ibatis.session.SqlSession
import org.apache.ibatis.type.TypeHandlerRegistry

/**
 * Created by 吴昊 on 2018/12/13.
 *
 * @author 吴昊
 * @date 2018
 * @version 0.1
 * @since 0.1
 */
class MybatisXmlLessConfiguration(val dbType: XmllessDbType) : MybatisConfiguration() {


  init {
    this.getTypeHandlerRegistry().register(List::class.java, JsonTypeHandler::class.java)
  }

  private val mybatisXmlLessMapperRegistry = MybatisXmlLessMapperRegistry(this)


  override fun <T> addMapper(type: Class<T>) {
    mybatisXmlLessMapperRegistry.addXMlLessMapper(type)
  }

  override fun addMappers(packageName: String, superType: Class<*>?) {
    mybatisXmlLessMapperRegistry.addMappers(packageName, superType)
  }

  override fun addMappers(packageName: String) {
    mybatisXmlLessMapperRegistry.addMappers(packageName)
  }

  override fun <T> getMapper(type: Class<T>, sqlSession: SqlSession): T {
    return mybatisXmlLessMapperRegistry.getXmlLessMapper(type, sqlSession)
  }

  override fun getMapperRegistry(): MapperRegistry {
    return mybatisXmlLessMapperRegistry
  }

  override fun hasMapper(type: Class<*>): Boolean {
    return mybatisXmlLessMapperRegistry.hasXmlLessMapper(type)
  }

}
